﻿
@page "/Fin/ReceivableDetail/BatchEdit"
@using nERP.ViewModel.Fin.ReceivableDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
  <div style="margin-bottom:10px;"> @WtmBlazor.Localizer["Sys.BatchEditConfirm"]</div>
  <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
    <BootstrapInput @bind-Value="@Model.LinkedVM.Seq"/>
    <Select @bind-Value="@Model.LinkedVM.ReceivableId" Items="AllReceivables" Id="g6bd9a90e21474c348843314323c64931"/>
    <Select @bind-Value="@Model.LinkedVM.SaleId" Items="AllSales" Id="g355daadc4eda45ec98417c8b268e4b19"/>
    <BootstrapInput @bind-Value="@Model.LinkedVM.Amount1"/>
    <BootstrapInput @bind-Value="@Model.LinkedVM.Amount2"/>
    <BootstrapInput @bind-Value="@Model.LinkedVM.Amount3"/>
    <BootstrapInput @bind-Value="@Model.LinkedVM.Amount4"/>
    <BootstrapInput @bind-Value="@Model.LinkedVM.Remark"/>
  </Row>

  <div class="modal-footer table-modal-footer">
    <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]"/>
    <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]"/>
  </div>

</ValidateForm>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private ReceivableDetailBatchVM Model = new ReceivableDetailBatchVM();
    private ValidateForm vform { get; set; }
    
    private async Task Submit(EditContext context)
    {
        Model.Ids = ids;
        await PostsForm(vform, "/api/Fin/ReceivableDetail/BatchEdit", (s) => WtmBlazor.Localizer["Sys.BatchEditSuccess", s], method: HttpMethodEnum.POST);
    }
            

    public void OnClose()
    {
        CloseDialog();
    }
    
    private List<SelectedItem> AllReceivables = new List<SelectedItem>();
    private List<SelectedItem> AllSales = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {
        
        
        AllReceivables = await WtmBlazor.Api.CallItemsApi("/api/Fin/ReceivableDetail/GetReceivables");
        AllReceivables.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllSales = await WtmBlazor.Api.CallItemsApi("/api/Fin/ReceivableDetail/GetSales");
        AllSales.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });

        await base.OnInitializedAsync();
    }
}
